package edu.zqu.collegeField.framework.easyexcel.utils;


import com.alibaba.excel.EasyExcel;

import edu.zqu.collegeField.framework.easyexcel.exceldata.ExcelData;
import edu.zqu.collegeField.framework.easyexcel.listener.ExcelListener;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.multipart.MultipartFile;

public class ExcelReadUtil {

    // 简单读取
    public static ExcelData simpleRead(MultipartFile file, Class<T> entityClass) throws Exception {
        ExcelListener<T> listener = new ExcelListener<>();
        EasyExcel.read(file.getInputStream(), entityClass, listener).sheet().doRead();
        return listener.getExcelData();
    }

    // 读取全部sheet
    // 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写
    public static ExcelData repeatedRead(MultipartFile file, Class<T> entityClass) throws Exception {
        ExcelListener<T> listener = new ExcelListener<>();
        EasyExcel.read(file.getInputStream(), entityClass, listener).doReadAll();
        return listener.getExcelData();
    }

}